#import <UIKit/UIKit.h>
#import "LockboxApp.h"
#include <unistd.h>
#include <sys/stat.h>

#define REDIRECT_NSLOG 0

int main(int argc, char **argv)
{
#if REDIRECT_NSLOG
    // Set permissions for our NSLog file
    umask(022);

    // Save stderr so it can be restored.
    int stderrSave = dup(STDERR_FILENO);
    NSLog(@"This goes to stderr");

    // Send stderr to our file
    FILE *newStderr = freopen("/var/root/lockbox.log", "a", stderr);
    NSLog(@"This goes to the file");
#endif

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int ret = UIApplicationMain(argc, argv, [LockboxApp class]);
	[pool release];

#if REDIRECT_NSLOG
    // Flush before restoring stderr
    fflush(stderr);
    fclose(newStderr);

    // Now restore stderr, so new output goes to console.
    dup2(stderrSave, STDERR_FILENO);
    close(stderrSave);
#endif
    
	return ret;
}
